from collections import defaultdict


class Solution:
    def firstUniqChar(self, s: str) -> int:
        mid_dic = defaultdict(int)
        for alpha in s:
            mid_dic[alpha] += 1
        for key, value in mid_dic.items():
            if value == 1:
                return s.index(key)


a = Solution()
print(a.firstUniqChar("leetcode"))
print(a.firstUniqChar("loveleetcode"))
